<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChTalkSettingConfig;
use Hyperf\Cache\Annotation\Cacheable;
use Hyperf\Config\Annotation\Value;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;
use Mine\Abstracts\AbstractMapper;

class ChTalkSettingConfigMapper extends AbstractMapper
{

    #[Value('cache.default.prefix')]
    protected string $prefix;

    public function assignModel()
    {
        $this->model = ChTalkSettingConfig::class;
    }


    #[Cacheable(prefix: 'ch_chat_setting_config',value: '#{uid}',ttl: 15 * 60)]
    public function findByUid(mixed $uid): ChTalkSettingConfig|Model|string|Builder|null
    {
        return $this->model::query()->where('uid', $uid)->first();
    }

    public function clearCache(mixed $uid): void
    {
        $redis = redis();
        $keyOne = $this->prefix . 'ch_chat_setting_config:'.$uid;
        $redis->del([$keyOne]);
    }
}